<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<div class="x_panel" xmlns="http://www.w3.org/1999/html">
    <div class="x_title">
        <ol class="breadcrumb pull-left">
            <li><a ng-click="navigateToPath('/cdns')">CDNs</a></li>
            <li><a ng-click="navigateToPath('/cdns/' + cdn.id)">{{cdn.name}}</a></li>
            <li><a ng-click="navigateToPath('/cdns/' + cdn.id + '/federations')">Federations</a></li>
            <li class="active">{{cname}}</li>
        </ol>
        <div class="pull-right" ng-show="!settings.isNew">
            <button class="btn btn-primary" title="Create Resolver" ng-click="createResolver()">Create Resolver</button>
            <div class="btn-group" role="group" uib-dropdown is-open="more.isopen">
                <button type="button" class="btn btn-default dropdown-toggle" uib-dropdown-toggle aria-haspopup="true" aria-expanded="false">
                    More&nbsp;
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu-right dropdown-menu" uib-dropdown-menu>
                    <li role="menuitem"><a ng-click="viewUsers()">View Users</a></li>
                </ul>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="x_content">
        <br>
        <form name="federationForm" class="form-horizontal form-label-left" novalidate>
            <fieldset>
                <legend>Federation Attributes</legend>
                <div class="form-group" ng-class="{'has-error': hasError(federationForm.cname), 'has-feedback': hasError(federationForm.cname)}">
                    <label class="control-label col-md-2 col-sm-2 col-xs-12">CNAME *</label>
                    <div class="col-md-10 col-sm-10 col-xs-12">
                        <input name="cname" type="text" class="form-control" ng-model="federation.cname" ng-pattern="/^\S*\.$/" required autofocus>
                        <small class="input-error" ng-show="hasPropertyError(federationForm.cname, 'required')">Required</small>
                        <small class="input-error" ng-show="hasPropertyError(federationForm.cname, 'pattern')">Invalid. Must contain no spaces and end with a dot.</small>
                        <span ng-show="hasError(federationForm.cname)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                    </div>
                </div>
                <div class="form-group" ng-class="{'has-error': hasError(federationForm.ttl), 'has-feedback': hasError(federationForm.ttl)}">
                    <label class="control-label col-md-2 col-sm-2 col-xs-12">TTL (seconds) *</label>
                    <div class="col-md-10 col-sm-10 col-xs-12">
                        <input name="ttl" type="number" class="form-control" placeholder="60 or greater" ng-model="federation.ttl" min="60" required autofocus>
                        <small class="input-error" ng-show="hasPropertyError(federationForm.ttl, 'required')">Required</small>
                        <small class="input-error" ng-show="hasPropertyError(federationForm.ttl, 'min')">60 or greater</small>
                        <span ng-show="hasError(federationForm.ttl)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                    </div>
                </div>
                <div class="form-group" ng-class="{'has-error': hasError(federationForm.dsId), 'has-feedback': hasError(federationForm.dsId)}">
                    <label class="control-label col-md-2 col-sm-2 col-xs-12">Delivery Service *</label>
                    <div class="col-md-10 col-sm-10 col-xs-12">
                        <select name="dsId" class="form-control" ng-model="federation.dsId" ng-options="ds.id as ds.xmlId for ds in deliveryServices" required>
                            <option value="">Select...</option>
                        </select>
                        <small class="input-error" ng-show="hasPropertyError(registerForm.dsId, 'required')">Required</small>
                    </div>
                </div>
                <div ng-if="settings.isNew">
                    <div class="form-group" ng-class="{'has-error': hasError(federationForm.userId), 'has-feedback': hasError(federationForm.userId)}">
                        <label class="control-label col-md-2 col-sm-2 col-xs-12">User *</label>
                        <div class="col-md-10 col-sm-10 col-xs-12">
                            <select name="userId" class="form-control" ng-model="federation.userId" ng-options="user.id as user.username for user in users" required>
                                <option value="">Select...</option>
                            </select>
                            <small class="input-error" ng-show="hasPropertyError(registerForm.userId, 'required')">Required</small>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-2 col-sm-2 col-xs-12">Description</label>
                    <div class="col-md-10 col-sm-10 col-xs-12">
                        <textarea name="description" rows="5" cols="17" class="form-control" ng-model="federation.description"></textarea>
                    </div>
                </div>
            </fieldset>
            <div ng-if="!settings.isNew">
                <fieldset>
                    <legend>Federation Resolvers</legend>
                    <table class="table responsive-utilities jambo_table" ng-show="resolvers.length > 0">
                        <thead>
                        <tr class="headings">
                            <th>IP</th>
                            <th>Type</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr ng-repeat="resolver in ::resolvers">
                            <td>{{::resolver.ipAddress}}</td>
                            <td>{{::resolver.type}}</td>
                            <td style="width:20px"><button type="button" class="btn btn-link" title="Delete Federation Resolver" ng-click="confirmDeleteResolver(resolver)"><i class="fa fa-trash"></i></button></td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="alert alert-dismissable alert-danger" ng-show="resolvers.length < 1">No federation resolvers</div>
                </fieldset>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" ng-show="!settings.isNew" ng-click="confirmDeleteFederation(federation)">Delete</button>
                <button type="button" class="btn btn-success" ng-disabled="federationForm.$pristine || federationForm.$invalid" ng-click="save(federation)">{{settings.saveLabel}}</button>
            </div>
        </form>
    </div>
</div>
